﻿using System.Dynamic;
using System.Security.Cryptography;

namespace RandomKeyGame
{/// <summary>
/// 一个练习打字和反应速度的小游戏
/// 随机跳出26个字母
/// 按对相应字母则增加一次正确，按错则增加一次错误
/// 最后会统计测试的字母数和用时
/// 如果不想玩了，按Esc退出
/// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {   //先定义程序开始的时间
            DateTime startTime = DateTime.Now;
            ConsoleKey input;
            Console.WriteLine("请确保您正在使用英文输入法");
            Console.WriteLine("按Enter键进入游戏");
            int countT = 0, countF = 0, count = 0;
            Random ran = new Random();
            if(Console.ReadKey().Key==ConsoleKey.Enter)
            {
                Console.Clear();
                do
                {
                    count++;
                    int RandKey = ran.Next(65, 91);
                    Console.Write((char)RandKey);
                    input = Console.ReadKey(true).Key;
                    if (RandKey == (int)input)
                        countT++;
                    //由于最后要按Esc退出，故要-1才是真正错误的数量
                    countF = count - countT-1;
                    Console.Clear();
                } while (input != ConsoleKey.Escape);//按Esc键退出
                DateTime finishTime = DateTime.Now;
                TimeSpan ts = finishTime - startTime;

                Console.WriteLine($"正确次数为：{countT}");
                Console.WriteLine($"错误次数为：{countF}");
                Console.WriteLine($"您测试了{countT + countF}个按键");
                Console.WriteLine("总用时：{0} 毫秒", ts.TotalMilliseconds);
            }
            

        }
    }
}